﻿using System;
using System.Data;
using System.Configuration;
using System.Reflection;

namespace br.com.SistemaChamados.Facade
{
    public class CacheFacade
    {
        private static CacheFacade __cacheFacade__ = new CacheFacade();

        private CacheFacade()
        {
            //Singleton Design Pattern
        }

        public static CacheFacade getInstance()
        {
            return __cacheFacade__;
        }

        public void setObjectInCache(string objectCacheName, object objectCache)
        {
            string methodName = "set" + objectCacheName;
            MethodInfo methodInfo = typeof(CacheFacade).GetMethod(methodName);
            object[] objectArgs = new object[1];
            objectArgs[0] = objectCache;
            methodInfo.Invoke(this, objectArgs);            
        }

        public Object getObjectFromCache(string objectCacheName)
        {
            object __object__ = new object();
            string methodName = "get" + objectCacheName;
            MethodInfo methodInfo = typeof(CacheFacade).GetMethod(methodName);
            __object__ = methodInfo.Invoke(this, null);
            return __object__;
        }

        //TODO: this is a test! Remove this!
        private string teste = "";

        public virtual string getMyString()
        {
            return "aiaiai";
        }

        public virtual void setMyString(string t)
        {
            teste = t;
        }
    }
}